namespace Isolation.TeamFoundationServer
{
	#region #using Directives

	using System.Linq;

	using Microsoft.TeamFoundation.Build.Client;

	#endregion

	internal class TfsBuildServer : ITfsBuildServer
	{
		private readonly IBuildServer buildServer;

		public TfsBuildServer(IBuildServer buildServer)
		{
			this.buildServer = buildServer;
		}

		#region Implementation of ITfsBuildServer

		public string[] QueryBuildDefinitions(string projectName)
		{
			try
			{
				return this.buildServer.QueryBuildDefinitions(projectName).Select(x => x.Name).ToArray();
			}
			catch (Microsoft.TeamFoundation.TeamFoundationServerException tfse)
			{
				throw new TeamFoundationServerException(tfse);
			}
		}

		public ITfsBuildDetail GetBuildDetail(string projectName, string buildDefinitionName)
		{
			try
			{
				return new TfsBuildDetail(this.buildServer.GetBuild(this.buildServer.GetBuildDefinition(projectName, buildDefinitionName).LastBuildUri));
			}
			catch (Microsoft.TeamFoundation.TeamFoundationServerException tfse)
			{
				throw new TeamFoundationServerException(tfse);
			}
		}

		#endregion
	}
}